<?php

/**
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * Copyright (c) 2010 Mr. Ynk: http://www.mrynk.nl
 */

/**
 * @author Michel Ypma: michel@mrynk.nl
 */

class Myto_CommandLine_CLI {

    private $commands;

    public function __construct()
    {
        
    }

    public function registerCommand( Myto_CommandLine_Command $pCommand )
    {
        $this->commands[] = $pCommand;
    }
    
    public static function stdout($msg)
    {
        if ( defined('STDOUT') )
            fwrite( STDOUT, $msg );
        else
            echo $msg;
    }

    public static function stderr($msg)
    {
        if ( defined( 'STDERR' ) )
            fwrite(STDERR, $msg);
        else
            echo $msg;
    }

    public static function getArguments()
    {
        if ( !isset( $_SERVER['argv'] ) || !is_array( $_SERVER['argv'] ) ) {
            if ( !isset( $GLOBALS['HTTP_SERVER_VARS']['argv'] ) || !is_array( $GLOBALS['HTTP_SERVER_VARS']['argv'] ) ) {
                return self::stderr("Myo_CommandLine_CLI: Could not read cmd args (register_argc_argv=Off?)");
            }
            return $GLOBALS['HTTP_SERVER_VARS']['argv'];
        }
        return $_SERVER['argv'];
    }

}
?>
